<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<title>充值卡管理</title>
</head>
<body>
	<jsp:include page="navigation.jsp"></jsp:include>
	<div class="container" style="margin-left: 190px; margin-bottom: 25px;">
		<div class="topbar-inner">
			<div class="myhead">
				<span class="crumb-name">充值卡管理</span>
			</div>
		</div>

		<div style="margin: 20px 20px 20px 20px; text-align: center;">
			<table class="table table-bordered table-hover table-striped">
				<thead>
					<tr>
						<th>积分数</th>
						<th>所需金钱</th>
						<th>修改时间</th>
						<th width="13%">操作</th>
					</tr>
				</thead>
				<c:forEach items="${ list }" var="l" varStatus="st">
					<tr>
						<form id="trForm_${ l.id }" action="hobbyedit" method="post">
							<td><input type="hidden" value="${ l.id }" name="id" /> <input type="text" class="form-control" value="${ l.point }" id="point_${ l.id }" name="point" /></td>
							<td><input type="text" class="form-control" value="${ l.money }" id="money_${ l.id }" name="money" /></td>
							<td><fmt:formatDate value="${ l.create_time }" pattern="yyyy-MM-dd HH:mm:ss" type="date" dateStyle="long" /></td>
							<td width="10%"><a href="javascript:" onclick="toEdit(${ l.id })">修改</a></td>
						</form>
					</tr>
				</c:forEach>
			</table>
		</div>
	</div>
	<script type="text/javascript">
$(function() {
    $('.submenu_4_3').addClass('submenu_native');
});

function toEdit(index) {
    var point = $('#point_' + index).val().replace(/\s+/g, '');
    if (!isInteger(point)) {
        alert('请填写正确的数字格式！');
        return false;
    }
    
    var money = $('#money_' + index).val().replace(/\s+/g, '');
    if (!isInteger(money)) {
        alert('请填写正确的数字格式！');
        return false;
    }
    
    $.ajax({
        type : 'post',
        url: "chargecardedit",
        data : $('#trForm_' + index).serialize(), 
        success : function (data) {
            console.log(data);
            if (data != null) {
                if (data.code == 0) {
                    alert('修改成功！');
                    window.location.reload();
                } else {
                    alert(data.message);
                }
                
            }
        }
    });
}

function toAdd() {
    var add_hobbyname = $('input[name=add_hobbyname]').val().replace(/\s+/g, '');
    if (isnumber()) {
        alert('兴趣爱好不能为空！');
        return false;
    }
    $.ajax({
        type : 'post',
        url: "hobbyedit",
        data : {hobby_name : add_hobbyname }, 
        success : function (data) {
            console.log(data);
            if (data != null) {
                if (data.code == 0) {
                    alert('修改成功！');
                    window.location.reload();
                } else {
                    alert(data.message);
                }
                
            }
        }
    });
}

function toDelete(id) {
    if (confirm("确定删除？")) {
        $.ajax({
            type : 'post',
            url: "hobbydelete",
            data : {id: id}, 
            success : function (data) {
                console.log(data);
                if (data != null) {
                    if (data.code == 0) {
                        alert('删除成功！');
                        window.location.reload();
                    } else {
                        alert(data.message);
                    }
                    
                }
            }
        });
    }
    
}
</script>
</body>
</html>